const Mock = require("mockjs");

const mockData = Mock.mock({
  "list|100": [
    {
      uid: "@id",
      controller: "com.qy.about.sys.admin.controller.ActionController",
      "appIntercept|1": [0, 1],
      "loginIntercept|1": [0, 1],
      "permsIntercept|1": [0, 1],
      created: "@datetime",
      module: "sys",
      actionKey: "/sys/action/del",
      remark: "@paragraph",
      id: "@id",
      updated: "@datetime",
      "status|1": [0, 1]
    }
  ]
});
module.exports = [
  {
    url: "/sys/action/sync",
    type: "post",
    response: () => {
      return {
        msg: "操作成功",
        code: 200,
        data: null,
        success: true,
        time: "2021-03-10 16:43:50"
      };
    }
  },
  {
    url: "/sys/action/upd",
    type: "post",
    response: config => {
      console.log(config.query);
      return {
        msg: "修改成功",
        code: 200,
        data: null,
        success: true,
        time: "2021-03-10 17:18:54"
      };
    }
  },
  {
    url: "/sys/action/page",
    type: "post",
    response: config => {
      console.log("请求", config.body);
      let { size, page } = config.body;
      let list = []
      if (size !== 99999) {
        let end = size * page - 1;
        let start = page == 1 ? 0 : (page - 1) * size;
        console.log("起点", start, end);
        // 通过分页计算得出
        list = mockData.list.filter(
          (item, index) => index >= start && index <= end
        );
      }else{
        list = mockData.list
      }
      return {
        msg: "获取接口的分页数据",
        code: 200,
        data: {
          pageNumber: 1,
          list,
          pageSize: size,
          totalPage: 3,
          totalRow: mockData.list.length,
          firstPage: true,
          lastPage: false
        },
        success: true,
        time: "2021-03-10 17:12:28"
      };
    }
  },
  {
    url: "/sys/action/del",
    type: "post",
    response: config => {
      console.log(config.body, config.query);
      return {
        msg: "删除成功",
        code: 200,
        data: null,
        success: true,
        time: "2021-03-10 16:43:50"
      };
    }
  },
  {
    url: "sys/action/clear",
    type: "post",
    response: config => {
      return {
        msg: "操作成功",
        code: 200,
        data: null,
        success: true,
        time: "2021-03-10 16:43:50"
      };
    }
  },
  {
    url: "sys/action/findForApp",
    type: "post",
    response: config => {
      return {
        msg: "获取可对外开放的接口",
        code: 200,
        data: [
          {
            uid: "6310db1e23a445c4bff6239c9e450c41",
            appIntercept: 1,
            module: "sys",
            actionKey: "/sys/action/get",
            remark: null,
            status: 1
          }
        ],
        success: true,
        time: "2021-03-12 09:38:16"
      };
    }
  }
];
